import { verifyAccessToken } from '~/utils/jwt-utils';
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
import { queryDatabase } from '~/functions';

export default eventHandler(async (event) => {
  const userinfo = verifyAccessToken(event);
  if (!userinfo) {
    return unAuthorizedResponse(event);
  }

  // 从数据库查询
  const results = <any[]>await queryDatabase('SELECT * FROM component', []);

  if (results.length > 0) {
    return useResponseSuccess(results);
  }
});
